package com.itheima.reggie.exception;

import com.itheima.reggie.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
@Slf4j
public class ControllerExceptionHandler {


    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public Result businessException(Exception e ){
        e.printStackTrace();
        log.error(e.getMessage());
        String message = e.getMessage();
        return Result.error(message);
    }

    @ExceptionHandler
    @ResponseBody
    public Result exceptionHandler(Exception e ){

        e.printStackTrace();
        log.error(e.getMessage());
        return Result.error( "我们正在维护" + e.getMessage() );

    }
}
